package com.hp.utils;


import com.hp.enums.ErrorCode;
import com.hp.enums.ExceptionCode;
import com.hp.exception.ServiceException;
import com.hp.response.ServiceResponse;

/**
 * response 生成器
 * @author hp
 */
public class ResponseGenerator {

    public static <T> ServiceResponse<T> builder(ExceptionCode errorDefine, String desc) {
        if (errorDefine == null) {
            throw new ServiceException(ErrorCode.ILLEGAL_PARAMETER);
        }
        return new ServiceResponse<T>().setCode(errorDefine.getCode()).setMessage(desc);
    }

    public static <T> ServiceResponse<T> builder(ExceptionCode errorDefine, T responseBody) {
        if (errorDefine == null) {
            throw new ServiceException(ErrorCode.ILLEGAL_PARAMETER);
        }
        return new ServiceResponse<T>().setData(responseBody).setCode(errorDefine.getCode()).setMessage(errorDefine.getDesc());

    }

    public static <T> ServiceResponse<T> builder(T responseBody) {
        ErrorCode errorDefine = ErrorCode.SUCCESS;
        return new ServiceResponse<T>().setData(responseBody).setCode(errorDefine.getCode()).setMessage(errorDefine.getDesc());

    }

    public static <T> ServiceResponse<T> builder() {
        ErrorCode errorDefine = ErrorCode.SUCCESS;
        return new ServiceResponse<T>().setCode(errorDefine.getCode()).setMessage(errorDefine.getDesc());

    }

    public static <T> ServiceResponse<T> builder(ExceptionCode errorDefine) {
        if (errorDefine == null) {
            errorDefine = ErrorCode.SUCCESS;
        }
        return new ServiceResponse<T>().setCode(errorDefine.getCode()).setMessage(errorDefine.getDesc());
    }

    public static <T> ServiceResponse<T> builder(String errorCode,String errorMsg) {

        return new ServiceResponse<T>().setCode(errorCode).setMessage(errorMsg);
    }

}
